/*
 * Simple Ajax call method.
 *
 * From http://en.wikipedia.org/wiki/XMLHttpRequest
 */
function ajax(url, vars, callbackFunction) {
  var request =  new XMLHttpRequest();
  request.open("POST", url, true);
  request.setRequestHeader("Content-Type",
                           "application/x-www-form-urlencoded");

  request.onreadystatechange = function() {
    if (request.readyState == 4 && request.status == 200) {
      if (request.responseText) {
        callbackFunction(request.responseText);
      }
    }
  };
  request.send(vars);
}

function getMyPlan() {
	ajax("ajaxPlan.do","action=load",function(data){document.getElementById("myplan").innerHTML=data;});
}

function saveMyPlan() {
	var content = document.getElementById("plancontent").value;
	var date = document.getElementById("date").value;
	if (content == "")
		alert("请输入内容:)");
	else if (date == "")
		alert("请输入时间:)");
	else {
		if (document.getElementById("publish_to_xiaonei").checked)
			testFeed(content);
		var post = "action=save&content="+content+"&date="+date;
		post = encodeURI(post);
		post = encodeURI(post);
		ajax("ajaxPlan.do", post,
			function(data){
				document.getElementById("savePlanSucc").style.display="";
				document.getElementById("myplan").innerHTML=data
			});
	}
}

function testFeed(content){
	feedSettings = {
		"template_bundle_id": 1,
		"template_data": {"images":[{"src":"http://hdn511.xnimg.cn/photos/hdn511/20090330/21/30/head_9Ncx_314828j204236.jpg", "href":"http://xiaonei.com/profile.do?id=240650143"}, {"src": "http://hd18.xiaonei.com/photos/hd18/20081204/16/01/head_6tiA_4215o198107.jpg", "href":"http://www.xiaonei.com"}]},
		"body_general": "here body_general",
		"callback": function(ok){console.log('here in feed callback!!');},
		"user_message_prompt": "随便写点东西吧:)",
		"user_message": content
	};
	XN.Connect.showFeedDialog(feedSettings);
}
